﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnglishLibrary;

namespace Helper
{
    public static class QueryHelper
    {
        public static string GenerateQueryStringByCateId(List<int> catesId)
        {
            if (catesId.Count <= 0)
                return string.Empty;

            //query format : CATEID = 1 OR CATEID = 2 OR CATEID = 3
            var query = new StringBuilder();

            foreach (var i in catesId)
                query.AppendFormat("CATEID = {0} OR ", i);
            
            //Remove the OR at the end (OR and the space)
            query.Remove(query.Length - 3, 3);

            return query.ToString();
        }

        public static string Validate(string query)
        {
            return query.Replace("'", "''").Replace("\"","''");
        }
    }
}
